home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 49 / Amiga Format CD49 (2000-01-17)(Future Publishing)(GB)(Track 1 of 3)[!][issue 2000-02].iso / -serious- / comms / other / novia / src / novia_io_main.c < prev    next >
Text File  |  1999-12-06  |  25KB  |  848 lines

  1. #include <exec/types.h>
  2. #include <stdlib.h>
  3. #include <exec/ports.h>
  4. #include <exec/io.h>
  5. #include <exec/tasks.h>
  6. #include <exec/lists.h>
  7. #include <pragma/exec_lib.h>
  8. #include <pragma/dos_lib.h>
  9. #include <pragma/intuition_lib.h>
  10. #include <pragma/gadtools_lib.h>
  11. #include <pragma/commodities_lib.h>
  12. #include <libraries/commodities.h>
  13. #include <novia/novia_UserList.h>
  14. #include <novia/novia_PortData.h>
  15. #include <novia/novia_config.h>
  16. #include <novia/novia_vde.h>
  17. #include <novia/novia_mail.h>
  18. #include <novia/novia_subboard.h>
  19. #include <novia/novia_types.h>
  20. #include <novia/novia_misc.h>
  21. #include <novia/novia_message.h>
  22. #include <novia/novia_gui.h>
  23. #include <exec/memory.h>
  24. #include <dos/dos.h>
  25. #include <string.h>
  26. #include <stdio.h>
  27. #include <intuition/intuition.h>
  28. #include <rexx/storage.h>
  29. #include <clib/rexxsyslib_protos.h>
  30. #include <novia/novia_funcs.h>
  31. #include <pragma/noviasys_lib.h>
  32.  
  33. //#define DEBUG
  34.  
  35. /* **** NOVIA_MAIN.C IMPORTS **** */
  36.  
  37. extern struct Task *MainTask;
  38. extern struct MsgPort *GUIPort;
  39. extern struct MsgPort *MainGUIPort;
  40. extern struct MsgPort *main_eventport;
  41. extern struct MsgPort *cxport;
  42. extern struct MainPortConfig *mainportconfig;
  43. extern struct List *client_list;
  44. extern CxObj  *broker;
  45.  
  46. /* **** PROTOTYPES **** */
  47.  
  48. ULONG Conread(char *string, char len,ULONG sigs);
  49. ULONG WaitSig(ULONG bitmask);
  50. BOOL SendMsg(MsgPort *port, APTR data, ULONG data_len, ULONG msg_type, ULONG cmd_type);
  51. void WaitConnect();
  52. struct EventMessage *SendEventMsg(MsgPort *toport, MsgPort *replyport, APTR data, ULONG msg_type);
  53. LONG handleCxMsg(struct Message *msg);
  54. void ioprintf(const char *string, ...);
  55.  
  56. /* **** SERIAL NETWORK PROTOTYPES **** */
  57.  
  58. extern BOOL SN_Open();
  59. extern void SN_Close();
  60. extern BOOL SN_CheckNetworkStatus();
  61. extern LONG SN_Send(APTR data, ULONG len);
  62. extern ULONG SN_Recv(char *string, char len, ULONG BreakBitMask);
  63. extern void SN_HangingUP();
  64. extern void SN_WaitConnect();
  65.  
  66. /* **** OTHER PROTOTYPES **** */
  67.  
  68. extern BOOL SendGUIMsg(LONG msgid,APTR data);
  69. extern void ReturnGUIMsg(GUIMsg *msg);
  70. extern void FreeGUIMsg(GUIMsg *msg);
  71.  
  72. /* ************************** */
  73.  
  74. #define PORTTYPE_MAIN 1
  75. #define PORTTYPE_CLIENT 0
  76.  
  77. #define PRIORITY_TOOL_TYPE            "CX_PRIORITY"
  78. #define POP_ON_START_TOOL_TYPE    "CX_POPUP"
  79. #define POPKEY_TOOL_TYPE            "CX_POPKEY"
  80. #define POP_KEY_ID     (86L)     /* pop up identifier             */
  81.  
  82. // LONG DisplayListcport(REG(a2) char **array,REG(a1) struct PortData *cport2)
  83.  
  84.  
  85.  
  86. ULONG Conread(char *string, char len, ULONG sigs)
  87. {
  88.     struct    Task                 *mytask    = FindTask(NULL);
  89.     struct    PortData         *cport    = (PortData *)mytask->tc_UserData;
  90.     ULONG                            sigmask    = 0;
  91.     struct    SerialNetwork     *sn        = cport->network.networkdata;
  92.     if (cport)
  93.     {
  94.         ULONG    sb_ConPort=0;
  95.         char quit=FALSE;
  96.         *string=0;
  97.         sb_ConPort=1<<cport->ConPort->mp_SigBit;
  98.         if (cport->win && cport->MonitorOpen && !cport->ConReadSend)
  99.         {
  100.             cport->ConRead->io_Command=(UWORD)CMD_READ;
  101.             cport->ConRead->io_Length=1;
  102.             cport->ConRead->io_Data=(APTR)cport->ConBuf;
  103.             SendIO((IORequest *)cport->ConRead);
  104.             cport->ConReadSend=TRUE;
  105.         }
  106.         while (!cport->ProgramClose && cport->network.online && !quit)
  107.         {
  108.             if (cport->network.isopen && cport->network.can_read)
  109.                 sigmask = SN_Recv(cport->network.ReadBuf, 1, sigs | sb_ConPort);
  110.             else
  111.             {
  112.                 sigmask = WaitSig(sigs | sb_ConPort);
  113.             }
  114.             if (sb_ConPort & sigmask)
  115.             {
  116.                 if (cport->MonitorOpen && cport->win && cport->ConReadSend)
  117.                 {
  118.                     if (CheckIO((IORequest *)cport->ConRead))
  119.                     {
  120.                         WaitIO((IORequest *)cport->ConRead);
  121.                         if (cport->ConRead->io_Actual > 0)
  122.                         {
  123.                            *string=*((char *)cport->ConRead->io_Data);
  124.                             quit=TRUE;
  125.                             cport->ConReadSend=FALSE;
  126.                         }
  127.                     }
  128.                 }
  129.  
  130.             }
  131.             if (*cport->network.ReadBuf)
  132.             {
  133.                 *string=*((char *)*cport->network.ReadBuf);
  134.                 quit=TRUE;
  135.             }
  136.             if (sigs & sigmask)
  137.                 quit=TRUE;
  138.         }
  139.     }
  140.  
  141.     if (sigs & sigmask)
  142.         return sigmask;
  143.     else
  144.         return NULL;
  145. }
  146.  
  147.  
  148. /*****************************************************************************************
  149.  * This function is a instand of exec's Wait() call. Use this for novia-internal         *
  150.  * message handling.                                                                     *
  151.  *****************************************************************************************/
  152.  
  153. ULONG WaitSig(ULONG bitmask)            // same as exec.library Wait()
  154. {
  155.     struct Task *mytask        = FindTask(NULL);                                            // own-task-address
  156.     struct PortData *cport    = (PortData *)mytask->tc_UserData;                    // PortData-structure
  157.     ULONG     sigs                    = 0;                                                            // waitsig-mask
  158.  
  159.     if (cport)                                                                                    // check value
  160.     {
  161.         struct message    *incommingmsg;
  162.         struct RexxMsg *rexxmsg;
  163.         ULONG                sb_ClientPort        = 1 << cport->LocalPort->mp_SigBit;    // sigbit of local Port
  164.         ULONG                sb_GUIPort;                                                            // sigbit of Main GUIPort
  165.         ULONG                sb_IDCMP;                                                            // sigbit of local Window-Port
  166.         ULONG                sb_rexxport            = 1 << cport->rexxport->mp_SigBit;    // sigbit of local rexxport
  167.         ULONG                sb_main_eventport    = 0;                                    // sigbit of Main eventport
  168.         ULONG                sb_nfs_port            = 1 << cport->nfs_port->mp_SigBit;    // sigbit of nfs_port
  169.         ULONG                sb_cxport            = 0;
  170.         char                buffer[200],
  171.                             Quit=FALSE,
  172.                             quit=FALSE,
  173.                             porttype;
  174.         ULONG                counter;
  175.  
  176.         if (mytask == MainTask)                                                                // testing for mainport
  177.         {
  178.             porttype                = PORTTYPE_MAIN;
  179.             sb_GUIPort            = 1 << MainGUIPort->mp_SigBit;
  180.             sb_main_eventport    = 1 << main_eventport->mp_SigBit;
  181.             if (cxport)
  182.                 sb_cxport        = 1 << cxport->mp_SigBit;
  183.         }
  184.         else
  185.             porttype                = PORTTYPE_CLIENT;
  186.  
  187.         if (cport->MonitorOpen)
  188.             sb_IDCMP=1<<cport->win->UserPort->mp_SigBit;
  189.         else
  190.             sb_IDCMP=0;
  191.  
  192.         while (!Quit && ((cport->network.online)|cport->connect_seq) && !cport->ProgramClose)
  193.         {
  194.             sigs=bitmask|sb_ClientPort|sb_GUIPort|sb_IDCMP|sb_rexxport|sb_main_eventport|sb_nfs_port|sb_cxport;
  195.             sigs=Wait(sigs);
  196.  
  197.             if (sb_rexxport & sigs)
  198.             {
  199.                 DoRexxMsg((RexxMsg *)GetMsg(cport->rexxport));
  200.             }
  201.  
  202. /************** IDCMP Message Handling *********************************************************/
  203.  
  204.             if ((sb_IDCMP & sigs) && cport->MonitorOpen)
  205.             {
  206.                 struct MenuItem        *item;
  207.                 ULONG                        item_number;
  208.                 ULONG                        menu_number;
  209.                 ULONG                        menucode;
  210.                struct Message            *msg=NULL;
  211.                 struct IntuiMessage    *imsg=NULL;
  212.                 while((imsg = (struct IntuiMessage *)GetMsg(cport->win->UserPort)))
  213.                 {
  214.                     if (imsg->Class==IDCMP_MENUPICK)
  215.                     {
  216.                         menucode = imsg->Code;
  217.                         item = ItemAddress(cport->win->MenuStrip, menucode);
  218.                         menu_number= MENUNUM(menucode);
  219.                         item_number=ITEMNUM(menucode);
  220.  
  221.                         if (porttype==PORTTYPE_MAIN)
  222.                         {
  223.                             switch(menu_number)
  224.                             {
  225.                                 case 0:                     // Menu Project
  226.                                     switch(item_number)
  227.                                     {
  228.                                         case 0:                    // ->About
  229.                                             break;
  230.                                         case 2:                    // ->Lock Consule
  231.                                             break;
  232.                                         case 3:                    // ->Close Window
  233.                                             break;
  234.                                         case 5:                    // ->Restart BBS
  235.                                             break;
  236.                                         case 6:                    // ->Reset Server
  237.                                             break;
  238.                                         case 8:                    // ->Quit
  239.                                             cport->ProgramClose   = TRUE;
  240.                                             cport->network.online = FALSE;
  241.                                             Quit=TRUE;
  242.                                             break;
  243.                                     }
  244.                                     break;
  245.                                 case 1:                     // Menu Services
  246.                                     switch(item_number)
  247.                                     {
  248.                                         case 0:                    // -> no calls
  249.                                             break;
  250.                                         case 1:                    // -> no anser
  251.                                             break;
  252.                                     }
  253.                                     break;
  254.                             }
  255.                         }
  256.                         else
  257.                         {
  258.                             switch(menu_number)
  259.                             {
  260.                                 case 0:                     // Menu Project
  261.                                     switch(item_number)
  262.                                     {
  263.                                         case 0:                    // ->About
  264.                                             break;
  265.                                         case 2:                    // ->Local Login
  266.                                             break;
  267.                                         case 4:                    // ->Close Window
  268.                                             Monitor_close();
  269.                                             break;
  270.                                         case 5:                    // ->Quit
  271.                                             break;
  272.                                     }
  273.                                     break;
  274.                                 case 1:                     // Menu Client
  275.                                     switch(item_number)
  276.                                     {
  277.                                         case 0:                    // -> offline
  278.                                             break;
  279.                                         case 1:                    // -> noanser
  280.                                             break;
  281.                                         case 2:                    // -> enter sysop chat
  282.                                             if (cport->SysopChat)
  283.                                             {
  284.                                                 cport->SysopChat = FALSE;
  285.                                             }
  286.                                             else
  287.                                             {
  288.                                                 char chatbuffer[10];
  289.                                                 cport->SysopChat = TRUE;
  290.                                                 ioprintf("c1---Sysop chatc7\n");
  291.                                                 while (!cport->ProgramClose && cport->network.online && cport->SysopChat)
  292.                                                 {
  293.                                                     Conread(chatbuffer,1,0);
  294.                                                     if (*chatbuffer == 13)
  295.                                                         Writeio("\n",-1);
  296.                                                     else
  297.                                                         Writeio(chatbuffer,1);
  298.                                                 }
  299.                                                 ioprintf("\nc1---existing Sysop charc7\n");
  300.                                             }
  301.                                             break;
  302.                                         case 3:                    // -> hanging up
  303.                                             cport->network.online = FALSE;
  304.                                             break;
  305.                                     }
  306.                                     break;
  307.                             }
  308.                         }
  309.                     }
  310.                     ReplyMsg((struct Message *)imsg);
  311.                 }
  312.             }
  313.  
  314. /************** MainEventPort Message Handling *********************************************************/
  315.  
  316.             if ((sb_main_eventport & sigs) && (porttype==PORTTYPE_MAIN))
  317.             {
  318.                 struct EventMessage *msg;
  319.                 while ((msg=(EventMessage *)GetMsg(main_eventport)))
  320.                 {
  321.                     if (msg->msg.mn_ReplyPort==main_eventport)
  322.                     {
  323.                         FreeVec(msg);
  324.                     }
  325.                     else
  326.                     {
  327.                         switch (msg->msg_type)
  328.                         {
  329.                             case GUIMSG_REDRAW_REMINDERLIST:
  330.                                 SendGUIMsg(GUIMSG_REDRAW_REMINDERLIST, 0);
  331.                                 break;
  332.                         }
  333.                         ReplyMsg((Message *)msg);
  334.                     }
  335.                 }
  336.             }
  337.  
  338. /************** GUI Message Handling ******************************************************************/
  339.  
  340.             if ((sb_GUIPort & sigs) && (porttype==PORTTYPE_MAIN))
  341.             {
  342.                 struct GUIMsg            *guimsg=NULL;
  343.                 struct PortData        *cport2;
  344.                 while((guimsg=(GUIMsg *)GetMsg(MainGUIPort)))
  345.                 {
  346.                     cport2=guimsg->data;
  347.                     switch (guimsg->cmdid)
  348.                     {
  349.                     case GUIMSG_CLOSE_MAINPORT:
  350.                         guimsg->cmdid=GUIMSG_CLOSE_WAIT_FOR_CLOSE_CMD;
  351. //                        cport->ProgramClose=TRUE;
  352.                         ioprintf("System shutdown, from GraficsUserInterface\n");
  353.                         cport->ProgramClose=TRUE;
  354.                         cport->network.online=FALSE;
  355.                         break;
  356.                     case GUIMSG_REPLY:
  357.                         FreeGUIMsg(guimsg);
  358.                         break;
  359.                     case GUIMSG_MPCONFIG_SAVE:
  360.                         SaveMainPortConfig(mainportconfig);
  361.                         break;
  362.                     case GUIMSG_MPCONFIG_USE:
  363.                         break;
  364.                     case GUIMSG_CLIENT_NEW:
  365.                         cport2=NewClientPort();
  366.                         if (cport2)SendGUIMsg(GUIMSG_CLIENT_EDIT,cport2);
  367.                         break;
  368.                     case GUIMSG_CLIENT_EDIT:
  369.                         if (cport2)SendGUIMsg(GUIMSG_CLIENT_EDIT,cport2);
  370.                         break;
  371.                     case GUIMSG_CLIENT_ONLINE:
  372.                         if (cport2->PortStatus==PORT_STATUS_CLOSE)
  373.                         {
  374.                             cport2->PortStatus=PORT_STATUS_WAITLOAD;
  375.                             Execute("run execute s:start_client",NULL,NULL);
  376.                         }
  377.                         break;
  378.                     case GUIMSG_CLIENT_OFFLINE:
  379.                         cport2->PortStatus=PORT_STATUS_OFFLINE;
  380.                         SendMsg(cport2->LocalPort,0,0,MSG_PORT_OFFLINE,0);
  381.                         SendGUIMsg(GUIMSG_CLIENT_CHANGE,cport2);
  382.                         break;
  383.                     case GUIMSG_CLIENT_UNLOAD:
  384.                         cport2->PortStatus=PORT_STATUS_CLOSE;
  385.                         SendMsg(cport2->LocalPort,0,0,MSG_PORT_CLOSE,0);
  386.                         SendGUIMsg(GUIMSG_CLIENT_CHANGE,cport2);
  387.                         break;
  388.                     case GUIMSG_CLIENT_USE:
  389.                         SendGUIMsg(GUIMSG_CLIENT_CHANGE,cport2);
  390.                         break;
  391.                     case GUIMSG_CLIENT_SAVE:
  392.                         SaveClientList();
  393.                         break;
  394.                     case GUIMSG_CLIENT_CANCEL:
  395.                         break;
  396.                     case GUIMSG_CLIENT_TOFRONT:
  397.                         SendMsg(cport2->LocalPort,0,0,MSG_PORT_TOFRONT,0);
  398.                         break;
  399.                     }
  400.                     if (guimsg->cmdid!=GUIMSG_REPLY)ReturnGUIMsg(guimsg);
  401.                 }
  402.             }
  403.  
  404. /************** Local-/Main Port Message Handling *********************************************************/
  405.  
  406.             if (sb_ClientPort & sigs)
  407.             {
  408.                 char                        *txtptr;
  409.                 struct PortData        *cport2;
  410.                 struct PortData2        *clientport;
  411.                 struct OnLineMessage    *olm,
  412.                                             *newolm;
  413.  
  414.                                                                                         /***** LOCAL Port Message Handling *****/
  415.  
  416.                 if (porttype == PORTTYPE_CLIENT)
  417.                 {
  418.                     while ((incommingmsg = (message *)GetMsg(cport->LocalPort)))
  419.                     {
  420.                         if (incommingmsg->msg.mn_ReplyPort == cport->LocalPort)
  421.                         {
  422.                             switch (incommingmsg->msg_type)
  423.                             {
  424.                                 case MSG_COMMAND:
  425.                                     switch (incommingmsg->cmd_type)
  426.                                     {
  427.                                         case CMD_WHO:
  428.                                             LF();
  429.                                             ioprintf("%s\n",incommingmsg->data);
  430.                                             break;
  431.                                     }
  432.                                     break;
  433.                             }
  434.                             if (incommingmsg->data_len)
  435.                                 FreeVec(incommingmsg->data);
  436.                             FreeVec(incommingmsg);
  437.                         }
  438.                         else
  439.                         {
  440.                             switch (incommingmsg->msg_type)
  441.                             {
  442.                                 case MSG_CHAT_BREAK:
  443.                                     ioprintf("chat break ***\n");
  444.                                     cport->ChatBreak=TRUE;
  445.                                     break;
  446.                                 case MSG_TEXT:
  447.                                     txtptr=(char *)incommingmsg->data;
  448.                                     ioprintf("c2%d\n",*txtptr);
  449.                                     break;
  450.                                 case MSG_COMMAND:
  451.                                     switch (incommingmsg->cmd_type)
  452.                                     {
  453.                                         case CMD_OLM:
  454.                                             olm=(OnLineMessage *)incommingmsg->data;
  455.                                             ioprintf("ON LINE MESSAGE\n");
  456.                                             switch (olm->OLM_type)
  457.                                             {
  458.                                                 case OLM_TYPE_NORMAL:
  459.                                                     ioprintf("ONLINE MESSAGE FROM: %d TO: %d\n:%s",olm->FromUser,olm->ToUser,olm->data);
  460.                                                     break;
  461.                                                 case OLM_TYPE_CHATACCEPT:
  462.                                                     ioprintf("\nChat Request accept\n");
  463.             //                                        OpenChatConnection(olm->FromUser);
  464.                                                     break;
  465.                                                 case OLM_TYPE_CHATREJECT:
  466.                                                     ioprintf("\nChat Request reject\n");
  467.                                                     break;
  468.                                                 case OLM_TYPE_BROADCAST:
  469.                                                     ioprintf("BROADAST MESSAGE FROM: %d\n:%s",olm->FromUser,olm->data);
  470.                                                     break;
  471.                                                 case OLM_TYPE_CHATREQUEST:
  472.                                                     if ((newolm=AllocVec(sizeof(OnLineMessage),MEMF_ANY|MEMF_CLEAR)))
  473.                                                     {
  474.                                                         newolm->ToUser=olm->FromUser;
  475.                                                         newolm->FromUser=cport->clientconfig.IDNumber;
  476.                                                         ioprintf("olm->FromUser: %d, LocalUser: %d\n",olm->FromUser,cport->LocalUser.IDNumber);
  477.                                                         ioprintf("ToUser: %d, FromUser: %d\n",newolm->ToUser,newolm->FromUser);
  478.                     
  479.                                                         ioprintf("CHAT REQUEST FROM: %d TO: %d\n:%s\n",olm->FromUser,olm->ToUser,olm->data);
  480.                                                         ioprintf("Do you like a little chat ?: ");
  481.                                                         if (Yesno(TRUE,0))
  482.                                                         {
  483.                                                             newolm->OLM_type=OLM_TYPE_CHATACCEPT;
  484.                                                             SendMsg(cport->MainPort,newolm,sizeof(OnLineMessage),MSG_COMMAND,CMD_OLM);
  485.     //                                                        OpenChatConnection(olm->FromUser);
  486.                                                         }
  487.                                                         else
  488.                                                         {
  489.                                                             newolm->OLM_type=OLM_TYPE_CHATREJECT;
  490.                                                             SendMsg(cport->MainPort,newolm,sizeof(OnLineMessage),MSG_COMMAND,CMD_OLM);
  491.                                                         }
  492.                                                     }
  493.                                                     break;
  494.                                             }
  495.                                             break;
  496.                                         case CMD_LOGOFF:
  497.                                             break;
  498.                                         case CMD_WHO:
  499.                                             LF();
  500.                                             ioprintf(incommingmsg->data);
  501.                                             break;
  502.                                     }
  503.                                     break;
  504.                                 case MSG_PORT_CLOSE:
  505.                                     cport->network.online    = FALSE;
  506.                                     cport->ProgramClose        = TRUE;
  507.                                     incommingmsg->msg_type    = MSG_REPLY_PORTCLOSEOK;
  508.                                     ReplyMsg((Message *)incommingmsg);
  509.                                     break;
  510.                                 case MSG_PORT_TOFRONT:
  511.                                     if (!cport->MonitorOpen)
  512.                                     {
  513.                                         Monitor_open();
  514.                                         if (cport->win)
  515.                                         {
  516.                                             sb_IDCMP=1<<cport->win->UserPort->mp_SigBit;
  517.                                             sigs=sb_ClientPort|sb_GUIPort|sb_IDCMP|sb_rexxport;
  518.                                         }
  519.                                     }
  520.                                     if (cport->win)
  521.                                     {
  522.                                         ScreenToFront(cport->win->WScreen);
  523.                                         WindowToFront(cport->win);
  524.                                     }
  525.                                     break;
  526.                                 case MSG_PING:
  527.                                     break;
  528.                             }
  529.                             ReplyMsg((Message *)incommingmsg);
  530.                         }
  531.                     }
  532.                 }
  533.  
  534.  
  535.                 else                                                                /***** MAIN Port Message Handling *****/
  536.  
  537.  
  538.  
  539.                 {
  540.                     while(incommingmsg=(message *)GetMsg(cport->LocalPort))
  541.                     {
  542.                         if (incommingmsg->msg.mn_ReplyPort == cport->LocalPort)
  543.                         {
  544.                             switch (incommingmsg->msg_type)
  545.                             {
  546.                                 case MSG_REPLY_PORTCLOSEFAILAT:
  547.                                     ioprintf("c3Port close c7% failat.\n");
  548.                                     break;
  549.                                 case MSG_REPLY_PORTCLOSEOK:
  550.                                     ioprintf("c3Port c7% is closed now.\n");
  551.                                     break;
  552.                                 case MSG_REPLY_PORTCLOSED:
  553.                                     ioprintf("c3Port c7% is closed now. (WARNING: THIS IS A OLD V0.01.02 MESSAGE !!!)\n");
  554.                                     break;
  555.                                 case MSG_REPLY_PORTOFFLINE:
  556.                                     ioprintf("c3Port c7% is offline now.\n");
  557.                                     break;
  558.                             }
  559.                             if (incommingmsg->data_len)
  560.                                 FreeMsg(incommingmsg->data);
  561.                             FreeMsg(incommingmsg);
  562.                         }
  563.                         else
  564.                         {
  565.                             switch (incommingmsg->msg_type)
  566.                             {
  567.                                 case MSG_CHAT_BREAK:
  568.                                     if ((cport2=FindClient(incommingmsg->cmd_type)))
  569.                     //                    SendMsg(cport2->LocalPort,0,0,MSG_CHAT_BREAK,0);
  570.                                         PutMsg(cport2->LocalPort,(Message *)incommingmsg);
  571.                                     break;
  572.                                 case MSG_TEXT:
  573.                                     if ((cport2=FindClient(incommingmsg->cmd_type)))
  574.                                         PutMsg(cport2->LocalPort,(Message *)incommingmsg);
  575.                                     break;
  576.                                 case MSG_COMMAND:
  577.                                     switch (incommingmsg->cmd_type)
  578.                                     {
  579.                                         case CMD_OLM:
  580.                                             ioprintf("olm->ToUser: %d\n",olm->ToUser);
  581.                                             break;
  582.                                         case CMD_WHO:
  583.                                             txtptr=AllocVec(1000,MEMF_ANY|MEMF_CLEAR);
  584.                                             incommingmsg->data=txtptr;
  585.                                             incommingmsg->data_len=1000;
  586.                                             sprintf(txtptr,"Port Username            Logon  Spd From                Where        \n");
  587.                                             txtptr=txtptr+strlen(txtptr);
  588.                                             sprintf(txtptr,"==== =================== ====== === =================== =============\n");
  589.                                             txtptr=txtptr+strlen(txtptr);
  590.                                             clientport=(PortData2 *)client_list->lh_Head;
  591.                                             while (clientport->port_node.ln_Succ)
  592.                                             {
  593.                                                 cport2=clientport->port_address;
  594.                                                 sprintf(buffer,"%4d %-19s %2d:%02d  %3d %-19s %s\n",
  595.                                                     cport2->clientconfig.IDNumber,
  596.                                                     cport2->LocalUser.Handle,
  597.                                                     cport2->LastLogin.hours,
  598.                                                     cport2->LastLogin.mins,
  599.                                                     cport2->CurrentCPS,
  600.                                                     cport2->LocalUser.City,
  601.                                                     cport2->Where);
  602.                                                 strcpy(txtptr,buffer);
  603.                                                 txtptr=txtptr+strlen(buffer);
  604.                                                 clientport=(PortData2 *)clientport->port_node.ln_Succ;
  605.                                             }
  606.                                             break;
  607.                                         case CMD_LOGOFF:
  608.                                             break;
  609.                                     }
  610.                                     break;
  611.                                 case MSG_INITPORT:
  612.                                     break;
  613.  
  614.                                 case MSG_PORT_CHANGE:        /* PORT-STATUS CHANGED */
  615. //                                    SendGUIMsg(GUIMSG_CLIENT_CHANGE,incommingmsg->data);
  616.                                     cport2=(PortData *)incommingmsg->data;
  617.                                     switch(((PortData *)incommingmsg->data)->PortStatus)
  618.                                     {
  619.                                         case PORT_STATUS_CONNECT:
  620.                                             ioprintf("\nc3Connect at Port c7 %sc3\n",cport2->clientconfig.IDNumber);
  621.                                             break;
  622.                                         case PORT_STATUS_LOGIN:
  623.                                             ioprintf("c3Login Sequence at Port c7 %sc3\n",cport2->clientconfig.IDNumber);
  624.                                             break;
  625.                                         case PORT_STATUS_ONLINE:
  626.                                             ioprintf("c3User: c7%s c3has login at Port c7 %dc3\n",cport2->LocalUser.Handle,cport2->clientconfig.IDNumber);
  627.                                             sprintf(buffer,"c3User: c7%s c3has login at Port c7 %dc3\n",cport2->LocalUser.Handle,cport2->clientconfig.IDNumber);
  628.                                             clientport=(PortData2 *)client_list->lh_Head;
  629.                                             while (clientport->port_node.ln_Succ)
  630.                                             {
  631.                                                 cport2=clientport->port_address;
  632.                                                 SendMsg(cport2->LocalPort,buffer,0,MSG_COMMAND,CMD_WHO);
  633.                                                 clientport=(PortData2 *)clientport->port_node.ln_Succ;
  634.                                             }
  635.                                             break;
  636.                                     }
  637.                                     break;
  638.  
  639.                                 case MSG_PORT_LOSTCARRIER:
  640.                                     cport2=(PortData *)incommingmsg->data;
  641.                                     ioprintf("c3User: c7%s c3has a lost carrier at Port c7 %dc3\n",cport2->LocalUser.Handle,cport2->clientconfig.IDNumber);
  642.                                     break;
  643.  
  644.                                 case MSG_PORT_LOGOFF:
  645.                                     cport2=(PortData *)incommingmsg->data;
  646.                                     ioprintf("c3User: c7%s c3has logoff at Port c7 %dc3\n",cport2->LocalUser.Handle,cport2->clientconfig.IDNumber);
  647.                                     sprintf(buffer,"c3User: c7%s c3has logoff at Port c7 %dc3\n",cport2->LocalUser.Handle,cport2->clientconfig.IDNumber);
  648.                                     clientport=(PortData2 *)client_list->lh_Head;
  649.                                     while (clientport->port_node.ln_Succ)
  650.                                     {
  651.                                         cport2=clientport->port_address;
  652.                                         SendMsg(cport2->LocalPort,buffer,0,MSG_COMMAND,CMD_WHO);
  653.                                         clientport=(PortData2 *)clientport->port_node.ln_Succ;
  654.                                     }
  655.                                     break;
  656.                                 case MSG_PORT_RING:
  657.                                     cport2=(PortData *)incommingmsg->data;
  658.                                     ioprintf("c3RING Detected at Port c7 %dc3\n",cport2->clientconfig.IDNumber);
  659.                                     break;
  660.                                 case MSG_PORT_CID:
  661.                                     cport2=(PortData *)incommingmsg->data;
  662.                                     ioprintf("c3Telnet Connect at Port c7 %dc3\n",cport2->clientconfig.IDNumber);
  663.                                     break;
  664.                             }             // end switch
  665.                             ReplyMsg((Message *)incommingmsg);
  666.                         }                // end id reply_message
  667.                     }                    // end while getmsg
  668.                 }                        // end test sigbit
  669.             }
  670.  
  671.  
  672. /************** NFS Message Handling *************************************************************/
  673.  
  674.             if (sb_nfs_port & sigs)
  675.             {
  676.                 struct NFSPacket *packet;
  677.  
  678.                 while ((packet = (NFSPacket *)GetMsg(cport->nfs_port)))
  679.                 {
  680.                     if (packet->nfs_msg.mn_ReplyPort == cport->nfs_port)
  681.                     {
  682.                         if (packet->nfs_result1 == RESULT_NFS_TEXTNOTIFY)
  683.                             if (packet->nfs_result2)
  684.                                 FreeVec(packet->nfs_result2);
  685.                         FreeVec(packet);
  686.                     }
  687.                     else
  688.                     {
  689.                         if (packet->nfs_result1 == RESULT_NFS_TEXTNOTIFY)
  690.                         {
  691.                             if (packet->nfs_result2)
  692.                             {
  693.                                 ioprintf("\n%s\n%d.%s:> ",packet->nfs_result2,cport->clientconfig.IDNumber,cport->currentdir->iib.fullpath);
  694.                             }
  695.                             ReplyMsg((Message *)packet);
  696.                         }
  697.                     }
  698.                 }
  699.             }
  700.  
  701. /************** Commodities Message Handling *************************************************************/
  702.             
  703.             if (sb_cxport & sigs)
  704.             {
  705.                 struct Message *msg;
  706.                 while ((msg = GetMsg(cxport)))
  707.                     handleCxMsg(msg);
  708.             }
  709.  
  710.             if (sigs & bitmask)Quit=TRUE;
  711.         }
  712.     }
  713.     return sigs;
  714. }
  715.  
  716. BOOL SendMsg(MsgPort *port, APTR data, ULONG data_len, ULONG msg_type, ULONG cmd_type)
  717. {
  718.     struct Task *mytask=FindTask(NULL);
  719.     struct PortData *cport=(PortData *)mytask->tc_UserData;
  720.     if (cport)
  721.     {
  722.         if (!(cport->LocalPort==port))
  723.         {
  724.             struct message *scheiss_telekom=MyAllocVec(sizeof(message),MEMF_ANY|MEMF_CLEAR,"IO_MAIN: SendMsg(), scheiss_telekom");
  725.             if (!scheiss_telekom)return FALSE;
  726.             if (port)
  727.             {
  728.                 if (data_len>0)
  729.                 {
  730.                     scheiss_telekom->data=MyAllocVec(data_len,MEMF_ANY,"Main: SendMsg(), scheiss_telekom (message)");
  731.                     if (scheiss_telekom->data==0)return FALSE;
  732.                     CopyMem(data,scheiss_telekom->data,data_len);
  733.                 }
  734.                 else
  735.                 {
  736.                     scheiss_telekom->data=data;
  737.                 }
  738.                 scheiss_telekom->msg.mn_Length=sizeof(message)+data_len;
  739.                 scheiss_telekom->msg.mn_ReplyPort=cport->LocalPort;
  740.                 scheiss_telekom->IDNumber=0;
  741.                 scheiss_telekom->IPNumber=cport->clientconfig.IDNumber;
  742.                 scheiss_telekom->data_len=data_len;
  743.                 scheiss_telekom->msg_type=msg_type;
  744.                 scheiss_telekom->cmd_type=cmd_type;
  745.                 scheiss_telekom->PortID=cport->clientconfig.IDNumber;
  746.                 /*    !!! Note are init by Alloc MEMF_CLEAR !!! */
  747.         //        scheiss_telekom->ln_Pred=msg_list->last;
  748.         //        scheiss_telekom->ln_Succ=0;
  749.         //        msg_list->last->ln_Succ=scheiss_telekom;
  750.         //        msg_list->last=scheiss_telekom;
  751.                 PutMsg(port,(Message *)scheiss_telekom);
  752.             }
  753.             else
  754.             {
  755.                 MyFreeVec(scheiss_telekom,"FREE IO_MAIN: scheiss_telekom");
  756.                 return FALSE;
  757.             }
  758.         }
  759.         else
  760.             return FALSE;
  761.     }
  762.     else
  763.         return FALSE;
  764. }
  765.  
  766.  
  767.  
  768.  
  769. struct EventMessage *SendEventMsg(MsgPort *toport, MsgPort *replyport, APTR data, ULONG msg_type)
  770. {
  771.     struct EventMessage *msg;
  772.     if ((msg=AllocVec(sizeof(EventMessage),MEMF_ANY|MEMF_CLEAR)))
  773.     {
  774.         msg->msg_type=msg_type;
  775.         msg->data=data;
  776.         msg->msg.mn_Length=sizeof(EventMessage);
  777.         msg->msg.mn_ReplyPort=replyport;
  778.         PutMsg(toport,(Message *)msg);
  779.     }
  780.     return msg;
  781. }
  782.  
  783. LONG handleCxMsg(struct Message *msg)
  784. {
  785.     LONG    result = 0;
  786.    LONG    msgid;
  787.    LONG    msgtype;
  788.  
  789.    msgid   = CxMsgID((CxMsg *) msg );
  790.    msgtype = CxMsgType((CxMsg *) msg );
  791.  
  792.    ReplyMsg(msg);
  793.  
  794.    switch(msgtype)
  795.    {
  796.       case CXM_IEVENT:
  797.          switch(msgid)
  798.          {
  799.             case POP_KEY_ID:
  800.                     Monitor_open();
  801.                     break;
  802.                 default:
  803.                     break;
  804.           }
  805.             break;
  806.       case CXM_COMMAND:
  807.          switch(msgid)
  808.          {
  809.             case CXCMD_DISABLE:
  810.                 ActivateCxObj(broker,0L);
  811.                break;
  812.             case CXCMD_ENABLE:
  813.                ActivateCxObj(broker,1L);
  814.                break;
  815.             case CXCMD_APPEAR:   /* Time to pop up the window         */
  816.             case CXCMD_UNIQUE:   /* Someone has tried to run us again */
  817.                     Monitor_open();
  818.                break;            /* the window                        */
  819.             case CXCMD_DISAPPEAR:
  820.                     Monitor_close();
  821.                break;
  822.             case CXCMD_KILL:
  823.                     {
  824.                         PortData *cport = (PortData *)FindTask(NULL)->tc_UserData;
  825.                         cport->ProgramClose=TRUE;
  826.                         cport->network.online = FALSE;
  827.                     }
  828.                break;
  829.             default:
  830.                printf("cx.c: handleCxMsg(Custom Command)\n");
  831.                break;
  832.          }     /* end switch(command) */
  833.          break;
  834.    }     /* end switch(msgtype) */
  835.     return result;
  836. }
  837.  
  838. void ioprintf(const char *string, ...)
  839. {
  840.     char *buffer=AllocVec(10000,MEMF_ANY|MEMF_CLEAR);
  841.     if (buffer)
  842.     {
  843.         vsprintf(buffer, string, unsigned int(&string + 1));
  844.         Writeio(buffer,-1);
  845.         FreeVec(buffer);
  846.     }
  847. }
  848.